package cn.tedu.charging.cost.repository;

import cn.tedu.charging.common.pojo.po.ChargingCostRulePO;
import cn.tedu.charging.cost.mapper.CostRuleMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class CostRuleRepositoryImpl implements CostRuleRepository{
    @Autowired
    private CostRuleMapper costRuleMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public ChargingCostRulePO getCostRule(Integer stationId, Integer hour) {
        //TODO 读取缓存 ?读取缓存key值设计 站场iD+时间段规则
        //TODO cache-aside 命中则返回缓存未命中则查询数据库 回填缓存
        QueryWrapper<ChargingCostRulePO> queryWrapper=new QueryWrapper<>();
        //station_id=?
        queryWrapper.eq("station_id",stationId);
        //每个不同时间段 尖峰平谷 start_time<=now()<end_time
        //lt < lte|le <= gt > gte|ge >=
        queryWrapper.le("start_time",hour);
        queryWrapper.gt("end_time",hour);
        return costRuleMapper.selectOne(queryWrapper);
    }
}
